package poker.entities;

public class Player {
	
	private String name;
	private int currentMoney;
	private Hand hand;
	private int number;
	private int lastPlacedBet;
	
	private boolean betPlaced = false, folded = false;
	
	public Player(){
		name = "GenericPlayer";
		currentMoney = 0;
		hand = null;
		betPlaced = false;
		folded = false;
	}
	
	public Player(String playerName, int startingMoneyAmount){
		name = playerName;
		currentMoney = startingMoneyAmount;
	}
	
	public Player(String playerName, int startingMoneyAmount, int number){
		name = playerName;
		currentMoney = startingMoneyAmount;
		this.number = number;
	}
	
	public void setHand(Hand hand){
		this.hand = hand;
	}
	
	/**
	 * 	getHand
	 * @return Hand in descending order.
	 */
	public Hand getHand(){
		hand.sortDescending();
		return hand;
	}
	
	public void discardCard(Card card){
		for(int index = 0; index < hand.getCards().size(); index++){
			if(card.equals(hand.getCards().get(index))){
				hand.removeCard(card);
			}
		}
	}
	
	public void fold(){
		hand = null;
		folded=true;
	}
	
	public void resetTurn(){
		betPlaced = false;
		folded = false;
		lastPlacedBet = -1;
	}
	
	public void placeBetOrRaise(int amount){
		currentMoney -= amount;
		lastPlacedBet = amount;
		betPlaced = true;
	}
	
	public boolean hasPlayed(){
		return betPlaced || folded?true:false;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getCurrentMoney() {
		return currentMoney;
	}

	public void setCurrentMoney(int currentMoney) {
		this.currentMoney = currentMoney;
	}

	public int getNumber() {
		return number;
	}

	public void setNumber(int number) {
		this.number = number;
	}

	public int getLastPlacedBet() {
		return lastPlacedBet;
	}

	public void setLastPlacedBet(int lastPlacedBet) {
		this.lastPlacedBet = lastPlacedBet;
	}

}
